/**
 * This software was produced for the U. S. Government
 * under Contract No. FA8721-09-C-0002, and is
 * subject to the Rights in Noncommercial Computer Software
 * and Noncommercial Computer Software Documentation Clause
 * (DFARS) 252.227-7014 (JUN 1995)
 * 
 * (c) 2009 The MITRE Corporation. All Rights Reserved.
 */
package com.mitre.spmif2opnet.generation.ir;

import java.util.LinkedList;
import java.util.List;

import com.mitre.spmif2opnet.generation.OpnetGraphConverter;
import com.mitre.spmif2opnet.opnet.network.Attr;

/**
 * Abstract representation of OPNET Jobs
 */
public class Job {
	/**
	 * Job name
	 */
	private String _name;
	/**
	 * Device name
	 */
	private String _device_name;
	/**
	 * Job priority
	 */
	private int _priority;
	/**
	 * Service requirements
	 */
	private double _service;
	/**
	 * Long job model name
	 */
	private String _long_model_name;
	/**
	 * Job class, i.e. what measurement standard
	 */
	private String _job_class;
	
	/**
	 * Default constructor
	 * @param name
	 * @param device_name
	 * @param priority
	 * @param service
	 * @param long_model_name
	 * @param job_class
	 */
	public Job(String name, String device_name, int priority, double service, String long_model_name, String job_class) {
		_name = name;
		_device_name = device_name;
		_priority = priority;
		_service = service;
		_long_model_name = long_model_name;
		_job_class = job_class;
	}

	/**
	 * Name accessor
	 * @return the name
	 */
	public String getName() {
		return _name;
	}
	
	/**
	 * Long model name accessor
	 * @return the name
	 */
	public String getLongModelName() {
		return _long_model_name;
	}
	
	/**
	 * Device name accessor
	 * @return the name
	 */
	public String getDeviceName() {
		return _device_name;
	}
	
	/**
	 * Unique job identifier
	 */
	private static int _job_id = 0;
	
	/**
	 * Get a unique job name
	 * @return the name
	 */
	public static String getNewJobName() {
		String task_name = "job" + Integer.toString(_job_id);
		++_job_id;
		return task_name;
	}

	/**
	 * Turn the job into XML attributes for a generic job list
	 * @param prefix attribute prefix
	 * @return list of XML attributes
	 */	
	public List<Attr> getAttributes(String prefix) {
		List<Attr> attrs = new LinkedList<Attr>();
		attrs.add(OpnetGraphConverter.makeAttr(prefix + "Name", _name));
		attrs.add(OpnetGraphConverter.makeAttr(prefix + "Measured System", _long_model_name)); 
		attrs.add(OpnetGraphConverter.makeAttr(prefix + "Job Class", _job_class)); 
		attrs.add(OpnetGraphConverter.makeAttr(prefix + "Average CPU Time", "constant (" + _service + ")"));  
		attrs.add(OpnetGraphConverter.makeAttr(prefix + "Average Page Faults", "None" , "true"));
		attrs.add(OpnetGraphConverter.makeAttr(prefix + "Average I/O Read Count", "None" , "true"));
		attrs.add(OpnetGraphConverter.makeAttr(prefix + "Average I/O Write Count", "None" , "true"));
		attrs.add(OpnetGraphConverter.makeAttr(prefix + "Average Read Block Size", "None" , "true"));
		attrs.add(OpnetGraphConverter.makeAttr(prefix + "Average Write Block Size", "None" , "true"));
		attrs.add(OpnetGraphConverter.makeAttr(prefix + "Memory Requirements", "Unknown" , "true"));
		return attrs;
	}

	/**
	 * Turn the job into XML attributes when living on a specific server
	 * @param prefix attribute prefix
	 * @return list of XML attributes
	 */	
	public List<Attr> getServerAttributes(String prefix) {
		List<Attr> attrs = new LinkedList<Attr>();
		attrs.add(OpnetGraphConverter.makeAttr(prefix + "Name", _name)); 
		attrs.add(OpnetGraphConverter.makeAttr(prefix + "CPU Partition", "Default", "true")); 
		attrs.add(OpnetGraphConverter.makeAttr(prefix + "Priority", Integer.toString(_priority))); 
		attrs.add(OpnetGraphConverter.makeAttr(prefix + "Storage Read Access Distribution", "Same as Write", "true")); 
		attrs.add(OpnetGraphConverter.makeAttr(prefix + "Storage Write Access Distribution", "Same as Read", "true")); 
		attrs.add(OpnetGraphConverter.makeAttr(prefix + "Transaction Trigger Mechanism", "Started by Application", "true")); 
		attrs.add(OpnetGraphConverter.makeAttr(prefix + "Transaction Limits", "Unlimited", "true")); 
		attrs.add(OpnetGraphConverter.makeAttr(prefix + "Calibration", "Same as Server Settings", "true")); 
		attrs.add(OpnetGraphConverter.makeAttr(prefix + "Threads", "1", "true")); 
		return attrs;
	}
}
